// mircoApp/new-auction/index/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    showPopup: false,
    contenDetail: "",
    storeArticle: [],
    good_list: [],
    plugin_name: "",

    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let language = wx.getStorageSync("langIndex");
    let yz_basic_info = wx.getStorageSync('yz_basic_info');
    let nowTime = new Date().getTime()
    this.setData({
      language: language.en,
      plugin_name: yz_basic_info.plugin_setting.new_auction.plugin_name,
      nowTime: nowTime
    });
    this.getData();
  },
  tabChange(e) {
    console.log(e)
    this.init();
    this.setData({
      active: e.detail.name
    })
    this.getList()
  },
  init() {
    this.setData({
      page: 1,
      total_page: 0,
      isLoadMore: true
    })
  },
  showPopupTap() {
    this.setData({
      showPopup: true
    })
  },
  closeBtn() {
    this.setData({
      showPopup: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  tapDetail(e) {
    let {
      item
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/mircoApp/new-auction/new_auction_detail/new_auction_detail?id=' + item.id,
    })
  },
  async getData() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.activity.categoryList"),
    })
    if (data.result) {
      data.data.category_list.unshift({id:0,name:'全部'})
      this.setData({
        category_list: data.data.category_list,
        active: 0,
        contenDetail: data.data.rule
      })
      this.init();
      this.getList();
    } else {
      app.tips(data.msg)
    }
  },
  async getList() {
    let json = {
      category_id: this.data.active == 0 ? "" : this.data.active
    };
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.activity"),
      data: json
    })
    if (data.result) {
      this.setData({
        good_list: data.data.data,
        total_page: data.last_page,
        isLoadMore: true
      })
      console.log(this.data.good_list)
    } else {
      app.tips(data.msg)
    }
  }
})